<?php

namespace App\Models;

use App\Engine\BaseModel;
use Illuminate\Database\Eloquent\Model;

class House extends BaseModel
{
    protected $fillable=['name','type','area','price','project','fenbu','explain','img','video','banner','wy_type','characteristic',
        'jz_type','zx_state','years','developers','address','sale_address','phone','state','infor','text_content','position','around'];
    public $timestamps = true;
    
    
    public function collection()
    {
        
        return $this->belongsTo('App\Models\Collection','id','hid');
    }

    public function types()
    {
        return $this->belongsTo('App\Models\HouseType','type','id');
    }

    public function projects()
    {
        return $this->belongsTo('App\Models\Project','project','id');
    }

    public function setImgAttribute($value)
    {
        if ($value=='')
           $value=[];
        $this->attributes['img']=json_encode($value);
    }

    public function getBannerAttribute($value)
    {
        return json_decode($value);
    }

    public function setBannerAttribute($value)
    {
        if ($value=='')
            $value=[];
        $this->attributes['banner']=json_encode($value);
    }

    public function getImgAttribute($value)
    {
        return json_decode($value);
    }

    public function setInforAttribute($value)
    {
        if($value=='')
            $value=[];
        $this->attributes['infor']=json_encode($value);
    }

    public function getInforAttribute($value)
    {
        return json_decode($value);
    }

    public function setPositionAttribute($value)
    {
        if($value=='')
            $value=[];
        $this->attributes['position']=json_encode($value);
    }

    public function getPositionAttribute($value)
    {
        return json_decode($value);
    }


}
